package net.lab0.wallstreet;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class Launcher
{
    public static void main(String[] args)
    throws IOException
    {
        String in = args[0];
        
        File input = new File(in);
        if (!input.exists())
        {
            System.err.println("Invalid path to test file : " + input.getAbsolutePath());
        }
        
        boolean verbose = false;
        if (args.length > 1 && args[1].equals("-v"))
        {
            verbose = true;
        }
        
        DataSource dataSource = new DataSource(in);
        dataSource.readData();
        
        List<Integer> result = AccountingDilemma.solve(dataSource.getBankTransfer(), dataSource.getDuePayments());
        
        if (verbose)
        {
            System.out.println("expected " + dataSource.getBankTransfer());
            System.out.println("list     " + dataSource.getDuePayments());
            System.out.println("solution " + result);
        }
        
        PrintWriter printWriter = null;
        try
        {
            printWriter = new PrintWriter("output.txt");
            if (result == null)
            {
                printWriter.println("NO SOLUTION");
            }
            else
            {
                for (int i : result)
                {
                    printWriter.println(ExampleGenerator.format.format(i / 100.0));
                }
            }
        }
        finally
        {
            if (printWriter != null)
            {
                printWriter.close();
            }
        }
    }
}
